import { JsCookies } from "@/utils/js-cookie";
import en_US from "ant-design-vue/lib/locale-provider/en_US.js";
import zh_CN from "ant-design-vue/lib/locale-provider/zh_CN.js";

export const moduleUser = {
  state: {
    authorization: JsCookies.getCookie("authorization"),
    // ant-design-vue plugins locale
    locale: JsCookies.getCookie("language") === "en_US" ? en_US : zh_CN,
    timezone: JsCookies.getCookie("timezone"),
    user: JsCookies.getCookie("user"),
    role: JsCookies.getCookie("role"),
    permission_set: JsCookies.getCookie("permission_set")
  },
  mutations: {
    SET_TIMEZONE: (state: any, timezone: string) => {
      state.timezone = timezone;
      JsCookies.setCookie("timezone", timezone);
    },

    SET_USER: (state: any, user: string) => {
      state.user = user;
      JsCookies.setCookie("user", user);
    },

    SET_LOCALE: (state: any, locale) => {
      JsCookies.setCookie("locale", locale);
    },

    SET_ROLE: (state: any, role: string) => {
      state.role = role;
      JsCookies.setCookie("role", role);
    },

    SET_PERMISSION_SET: (state: any, permission_set: string) => {
      state.permission_set = permission_set;
      JsCookies.setCookie("permission_set", permission_set);
    },

    SET_LANGUAGE: (state: any, language) => {
      state.language = language;
      JsCookies.setCookie("language", language);
    }
  },
  actions: {}
};

export default moduleUser;
